/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Gao zhao xu
 * Date: 2023-09-11
 * Time: 9:27
 */

class B<T extends Comparable<T>>{
    public T findMax(T[] arr){
        T max = arr[0];
        for (int i  = 0; i < arr.length; i++) {
            if (max.compareTo(arr[i]) < 0){
                max = arr[i];
            }
        }
        return max;
    }
}

class B1{
    public static <T extends Comparable<T>>T findMax(T[] arr){
        T max = arr[0];
        for (int i  = 0; i < arr.length; i++) {
            if (max.compareTo(arr[i]) < 0){
                max = arr[i];
            }
        }
        return max;
    }
}
public class 使用泛型求最大值 {
    public static void main(String[] args) {
        Integer[] a = {0, 12, 45, 450};
        Integer max = B1.findMax(a);
        System.out.println(max);
    }
    public static void main1(String[] args) {
        B<Integer> b = new B();
        Integer[] arr = {0, 1, 2 , 5 , 10};
        Integer max = b.findMax(arr);
        System.out.println(max);
        System.out.println("===============");
        B<String> c = new B<>();
        String[] arr1 = {"asd", "asb", "cgs"};
        String max1 = c.findMax(arr1);
        System.out.println(max1);
    }
}
